﻿package com.googlecode.openauth.web.service.impl;

import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.googlecode.openauth.web.dao.IAuthrizeDao;
import com.googlecode.openauth.web.entity.Authrize;

public class AuthrizeTester {

	private static ApplicationContext context;
	private static IAuthrizeDao auth;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		context = new ClassPathXmlApplicationContext("applicationContext.xml");
		auth = (IAuthrizeDao) context.getBean("authDao");
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Test
	public void testGetAll() {
		List<Authrize> list = auth.getAuthrize();
		if (list != null) {
			for (Authrize au : list) {
				System.out.println(au.getActionid() + " " + au.getUuid()
						+ au.getActionname() + " " + au.getActiondesc());
			}
		}
	}

	@Test
	public void testAddAuth() {
		Authrize temp = new Authrize();
		temp.setActionname("测试1");
		temp.setActiondesc("测试desc");
		auth.addAuthrize(temp);
		System.out.println();
	}

	@Test
	public void testUpdateAuth() {
		Authrize temp = new Authrize();
		temp.setActionid(41);
		temp.setActionname("test1modify");
		temp.setActiondesc("test1desc");
		auth.updateAuthrize(temp);
	}

	@Test
	public void testDelAuth() {
		Authrize temp = new Authrize();
		temp.setActionid(41);
		auth.delAuthrize(temp);
	}

	@Test
	public void testGetAuth() {
		List<Authrize> list = auth.getAuthrizeByName("管理");
		if (list != null) {
			for (Authrize au : list) {
				System.out.println(au.getActionid() + " " + au.getUuid()
						+ au.getActionname() + " " + au.getActiondesc());
			}
		}
		List<Authrize> list1 = auth.getAuthrizeByDesc("desc");
		if (list1 != null) {
			for (Authrize au : list1) {
				System.out.println(au.getActionid() + " " + au.getUuid()
						+ au.getActionname() + " " + au.getActiondesc());
			}
		}
	}

}
